//
//  SectionTableViewController.swift
//  DriverSchoolAPP
//
//  Created by Logel on 2017/5/11.
//  Copyright © 2017年 Logel. All rights reserved.
//

import UIKit

class SectionTableViewController: UITableViewController,LgCallBack {
    var pList = [Learn]()
    override func viewDidLoad() {
        super.viewDidLoad()
        getData()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return pList.count
    }

    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "reuseCell", for: indexPath) as! SectionTableViewCell
        cell.learn = pList[indexPath.row]
        // Configure the cell...

        return cell
    }
    
    func getData(){
        asyn_req_post(method: M_Learning, cb: self, p: ["accountId":user.accountId as AnyObject])
    }
    
    func callBack(method: String, data: AnyObject) {
        let j = JSON(data)
        print(j)
        let head = parseMobileHead(x: j["MobileHead"])
        if head.code == "1" {
            pList.append(contentsOf:parseLearnList(all: j["MobileBody"].array!))
            
        }
        
        tableView.reloadData()

    }

    

}
